PowerShell Script for Deploying All Assemblies in a Folder to the GAC

Comments 0

Share to social media

As a SharePoint developer, I find it a lot easier to manually deploy files to the GAC during development instead of allowing Visual Studio to do a complete retract / redeploy.  There are tools out there like CKS Dev that give you the “Copy to GAC” option directly from a project, but I’ve found that option does not always get everything in the GAC that I want.  As such, I’ve started adding a simple post-build command to copy all newly built DLLs into a “Compiled DLLs” folder in the solution root so I have a consolidated set of assemblies to deploy out to the GAC.  Then I run the following PowerShell script that deploys all of the assemblies found in a folder out to the GAC:

$gacUtilLocation = “C:Program Files (x86)Microsoft SDKsWindowsv7.0ABinx64gacutil.exe”;

get-childitem * -include *.dll,*.exe | foreach-object {
    Write-Host “Adding” $asm.FullName
    $asm = [System.Reflection.Assembly]::LoadFile($_)
    $command = “&`”{0}`”/nologo /i `”{1}`”” -f $gacUtilLocation,$_
    invoke-expression $command
}

Load comments

About the author

Damon Armstrong

See Profile

Damon Armstrong is a consultant with SystemwarePS in Dallas, Texas. He is also a blogger and author of Pro ASP.NET 2.0 Website Programming and SharePoint 2013 Essentials for Developers. He specializes in the Microsoft stack with a focus on web technologies like MVC, ASP.NET, JavaScript, and SharePoint. When not staying up all night coding, he can be found watching a bunch of kids, studying Biblical topics, playing golf, or recovering from staying up all night coding.